﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SynoManager.Rss;
using System.Text.RegularExpressions;

namespace SynoManager.DownloadStation.Search
{
    [SearchEngine("The Pirate Bay", "http://www.thepiratebay.org/", "Grad \"Flard\" van Horck", "1.0", "")]
    public class PirateBaySearchEngine : HttpSearchEngineBase
    {
        protected override string RequestUri
        {
            get { return "http://thepiratebay.org/search/{0}/0/99/0"; }
        }

        /*
<tr(?: class="alt")?>
<td class="vertTh"><a href="(?<CategoryUrl>[//a-z0-9]+)" title="(?:.*)">(?<Category>.*)</a></td>
<td><a href="(?<MoreInfoUrl>.*)" class="detLink" title="(.*)">(?<Title>.*)</a></td>
<td>(?<Date>.*)</td>
<td><a href="(?<DownloadUrl>.*)" title="(?:.*)"><img src="http://static.thepiratebay.org/img/dl.gif" class="dl" alt="(?:.*)" /></a>(?:.*)</td>
<td align="right">(?<Size>.*)</td>
<td align="right">(?<Seeders>.*)</td>
<td align="right">(?<Leechers>.*)</td>
</tr>
         */

        protected override string Regex
        {
            get
            {
                return "<tr(?: class=\"alt\")?>\r\n<td class=\"vertTh\"><a href=\"(?<C" +
                       "ategoryUrl>[//a-z0-9]+)\" title=\"(?:.*)\">(?<Category>.*)</" +
                       "a></td>\r\n<td><a href=\"(?<MoreInfoUrl>.*)\" class=\"detLink\" " +
                       "title=\"(.*)\">(?<Title>.*)</a></td>\r\n<td>(?<Date>.*)</td>\r\n" +
                       "<td><a href=\"(?<DownloadUrl>.*)\" title=\"(?:.*)\"><img src" +
                       "=\"http://static.thepiratebay.org/img/dl.gif\" class=\"dl\" " +
                       "alt=\"(?:.*)\" /></a>(?:.*)</td>\r\n<td align=\"right\">(?<Siz" +
                       "e>.*)</td>\r\n<td align=\"right\">(?<Seeders>.*)</td>\r\n<td ali" +
                       "gn=\"right\">(?<Leechers>.*)</td>\r\n</tr>";
            }
        }

        protected override HttpSearchResultBase CreateResult(Match match)
        {
            return new PirateBaySearchResult(this, match);
        }
    }
}
